package com.tienon.message.Test;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import javax.annotation.Resource;

import org.junit.Test;

import com.tienon.message.entity.Push_App;
import com.tienon.message.entity.Raw_msg_batch;
import com.tienon.message.mapper.Push_AppMapper;
import com.tienon.message.mapper.Raw_msg_batchMapper;
import com.tienon.message.service.LoadRawMsgService;
import com.tienon.message.service.LoadSendMsgService;
import com.tienon.message.thread.LoadSendMsgTasks;
import com.tienon.message.thread.task.AppSendMsgDBSubTask;
import com.tienon.message.thread.task.AppSendMsgTask;
import com.tienon.message.util.SpringUtil;

public class TestTasksService extends UnitTestEnv{

	@Resource
	private LoadRawMsgService rawService;
	
	@Resource
	private LoadSendMsgService sendService;
	
	@Resource
	private Raw_msg_batchMapper rawDao; 
	
	@Resource
	private Push_AppMapper appDao;
	
	//ORA-00913: 值过多
	//ORA-00947: 没有足够的值
	//出现不支持的 SQL92 标记: 654: SERIAL
	@Test
	public void testLoadRawMsgTasksService(){
		Raw_msg_batch data = new Raw_msg_batch();
		data.setBatId(888);
		//data.setSerail(333);
		data.setBsnCd("123456");
		data.setFilter(1);
		data.setOccDate(new Date());
		data.setSendTime(new Date());
		data.setSendNow(1);
		data.setBatSlice(1);
		data.setMsgType(1);
		data.setMsg("123456");
		data.setSplitFlag(1);
		data.setSendWay(1);
		data.setBatOrder(1);
		data.setSendTimes(1);
		data.setPrior(1);
		data.setReportFlag(1);
		
		data.setOccDate(new Date());
		data.setLinkFlag(1);
		data.setState(1);
		data.setOccTime(new Date());
		
		
		
		Future<Boolean> f = rawService.loadRawMsgTask(data);
		
		try {
			System.out.println(f.get());
		} catch (InterruptedException e) {
			
			e.printStackTrace();
		} catch (ExecutionException e) {
			
			e.printStackTrace();
		} 
	}
	
	@Test
	public void testSingleSendMsgService(){
		
		Push_App appData = new Push_App();
		appData.setBatId(888);
		appData.setSerial(11);
		appData.setSplitId(1);
		appData.setFilter(1);
		appData.setOccDate(new Date());
		appData.setFee(100);
		appData.setSendNow(1);
		appData.setSendTime(new Date());
		appData.setSplitTotal(111);
		appData.setMsgType(1);
		appData.setMsg("TEST");
		appData.setSplitFlag(1);
		appData.setSendWay(1);
		appData.setBsnCd("123456");
		appData.setSendTimes(1);
		appData.setFeeType(1);
		appData.setOutChannle("1");
		appData.setPrior(1);
		appData.setReportFlag(1);
		appData.setOccDate(new Date());
		appData.setLinkFlag(1);
		appData.setState(1);
		appData.setOccTime(new Date());
		appData.setOutChanCustomId("2");
		
		
		Future<Boolean> future = LoadSendMsgTasks.loadAppSendMsgTask(appData);
		
		try {
			System.out.println(future.get());
		} catch (InterruptedException e) {
			
			e.printStackTrace();
		} catch (ExecutionException e) {
			
			e.printStackTrace();
		}		
		
		
		
		
		
		
	}
	
	@Test
	public void testAppSendMsgService(){
		
		List<Push_App> appDatas = new ArrayList<Push_App>();		
		List<Raw_msg_batch> rawDatas = this.rawDao.selectByBatId(111);
		
		for(Raw_msg_batch rawData : rawDatas){
			
			Push_App appData = new Push_App();
			appData.setBatId(rawData.getBatId());
			appData.setSerial(rawData.getSerail());
			appData.setSplitId(1);
			appData.setFilter(rawData.getFilter());
			
			appData.setFee(100);
			appData.setSendNow(rawData.getSendNow());
			appData.setSendTime(rawData.getSendTime());
			appData.setSplitTotal(5);
			appData.setMsgType(rawData.getMsgType());
			appData.setMsg(rawData.getMsg());
			appData.setSplitFlag(rawData.getSplitFlag());
			appData.setSendWay(rawData.getSendWay());
			appData.setBsnCd(rawData.getBsnCd());
			appData.setSendTimes(rawData.getSendTimes());
			appData.setFeeType(1);
			appData.setOutChannle("11");
			appData.setPrior(rawData.getPrior());
			appData.setReportFlag(rawData.getReportFlag());
			appData.setOccDate(rawData.getOccDate());
			appData.setLinkFlag(rawData.getLinkFlag());
			appData.setState(4);
			appData.setOccTime(rawData.getOccTime());
			appData.setOutChanCustomId("qwe");
			appDatas.add(appData);
			
			System.out.println(rawData);
		}
		List<Future<Boolean>> futures = sendService.loadAppSendMsgTasks(appDatas);
		for(Future<Boolean> f : futures){
			try {
				System.out.println(f.get());
			} catch (InterruptedException e) {
				e.printStackTrace();
			} catch (ExecutionException e) {
				
				e.printStackTrace();
			}
		}
		
	}
	
}
